import request from '@/utils/request'
import { praseStrEmpty } from '@/utils/index'

// 查询用户列表
export function listUserTab(params) {
  return request({
    url: 'system/user/selectUserList',
    method: 'get',
    params,
  })
}

export function listClientAccont(params) {
  return request({
    url: '/system/user/listClientAccont',
    method: 'get',
    params,
  })
}

export function getUser(userId) {
  return request({
    url: `/system/user/${ praseStrEmpty(userId) }`,
    method: 'get',
  })
}
// 删除用户信息
export function delUser(userIds) {
  return request({
    url: `/system/user/${ userIds }`,
    method: 'delete',
  })
}

export function resetUserPwd(userId, password) {
  const data = {
    userId,
    password,
  }
  return request({
    url: '/system/user/resetPwd',
    method: 'put',
    data,
  })
}
// 修改用户信息
export function updateUser(data) {
  return request({
    url: '/system/user/update',
    method: 'post',
    data,
  })
}

export function addUser(data) {
  return request({
    url: '/system/user',
    method: 'post',
    data,
  })
}

// export function addclientAccont(data) {
//   return request({
//     url: '/system/user',
//     method: 'post',
//     data,
//   })
// }

export function changeUserStatus(userId, status) {
  return request({
    url: '/system/user/changeStatus',
    method: 'put',
    data: {
      userId,
      status,
    },
  })
}

export function uploadAvatar(data) {
  return request({
    url: '/system/user/profile/avatar',
    method: 'post',
    data,
  })
}

export function getUserProfile() {
  return request({
    url: '/system/user/profile',
    method: 'get',
  })
}

export function updateUserProfile(data) {
  return request({
    url: '/system/user/profile',
    method: 'put',
    data,
  })
}

export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword,
  }
  return request({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: data,
  })
}

// export function uploadImg(data) {
//   return request({
//     url: "/system/user/profile/updateAvatar",
//     method: "post",
//     data,
//   });
// }
// 业务员，提货员，客服员，结算员
export function queryBusinessManager(status) {
  return request({
    url: '/system/user/selectUserDropDownBox',
    method: 'get',
    params: status,
  })
}

export function uploadImg(data) {
  return request({
    url: '/system/user/profile/updateAvatar',
    method: 'post',
    data,
  })
}

export function getImage(data) {
  return request({
    url: '/system/user/profile/getImage',
    method: 'get',
    data,
    responseType: 'blob',
  })
}
// 根据部门id 查询用户
export function getUsersInfo(deptId) {
  return request({
    url: `/system/user/selectUsersByDeptId/${ deptId }`,
    method: 'get',
  })
}
// 获取部门下拉树
export const treeselect = () => request({
  url: '/system/dept/treeselect',
})
// 根据id获取部门下拉树列表
export function userDeptTreeselect(userId) {
  return request({
    url: `system/dept/userDeptTreeselect/${ userId }`,
    method: 'get',
  })
}
// 修改用户数据权限
export function updateDataScope(data) {
  return request({
    url: '/system/user/dataScope',
    method: 'put',
    data,
  })
}
// 密码解密
export function passwordDecryption(username) {
  return request({
    url: `system//user/customerDecryption/${ username }`,
  })
}
